package com.deke.order.service.Impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.deke.entity.ShoucangCourse;
import com.deke.order.dao.ShoucangCourseDao;
import com.deke.order.service.QianCourseCollectService;
import com.deke.order.vo.ShouCangCourseVo;
import com.deke.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ：Username 刘亦辰（59372312@qq.com）
 * @date ：Created in 2022/12/30 15:17
 * @description：
 * @modified By：
 * @version:
 **/
@Service
public class QianCourseCollectServiceImpl implements QianCourseCollectService {
    @Autowired
    private ShoucangCourseDao shoucangCourseDao;

    @Override
    public Result findFavoriteCourse(ShouCangCourseVo shouCangCourseVo) {
        Integer shouChangStatus= 0;
        QueryWrapper<ShoucangCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("member_id",shouCangCourseVo.getMemberid());
        queryWrapper.eq("course_id",shouCangCourseVo.getCourseid());
        ShoucangCourse shoucangCourse = shoucangCourseDao.selectOne(queryWrapper);
        if (ObjectUtil.isNotEmpty(shoucangCourse)){
            shouChangStatus=1;
            return new Result(2000,"已收藏",shouChangStatus);
        }
        return new Result(2000,"未收藏",shouChangStatus);
    }

    /**
     * @create by: Username 刘亦辰 
     * @description: 收藏课程 
     * @create time: 2022/12/30 15:25
     * @param null 
     * @return :  
     **/
    @Override
    public Result addFavoritescourse(ShouCangCourseVo shouCangCourseVo) {
        ShoucangCourse shoucangCourse = new ShoucangCourse();
        shoucangCourse.setCourseId(shouCangCourseVo.getCourseid());
        shoucangCourse.setMemberId(shouCangCourseVo.getMemberid());
        int insert = shoucangCourseDao.insert(shoucangCourse);
        if (ObjectUtil.isNotEmpty(insert)){
            return new Result(2000,"收藏成功");
        }
        return new Result(0000,"收藏失败");
    }


    /**
     * @create by: Username 刘亦辰 
     * @description: 删除收藏 
     * @create time: 2022/12/30 15:29
     * @param null
     * @return :  
     **/
    @Override
    public Result deleteFavoriteCourse(ShouCangCourseVo shouCangCourseVo) {
        QueryWrapper<ShoucangCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("member_id",shouCangCourseVo.getMemberid());
        queryWrapper.eq("course_id",shouCangCourseVo.getCourseid());
        int delete = shoucangCourseDao.delete(queryWrapper);
        if (ObjectUtil.isNotEmpty(delete)){
            return new Result(2000,"取消收藏成功");
        }
        return new Result(0000,"取消收藏失败");
    }

}